#ifndef ELEMENTSWITCH_H
#define ELEMENTSWITCH_H

#include "GameElement.h"
#include "Drawing.h"
#include "AnimationObj.h"

#define MAX_TARGETS 10
typedef QuickArray<GameElement*,MAX_TARGETS> SWITCH_TARGET_ARRAY;

struct switchAnimation:public animationObj{
    bool on;

    switchAnimation(){
        on=false;
    }

    void setOn(bool _on){
        on=_on;
    }

    void render(){
        static GLuint dlID=0;

        glPushMatrix();
        if(on)glColor3f(0,1.0,0);
        else glColor3f(1.0,0,0);

        glTranslatef(0.3,0,0.3);
        glRotatef(-45 + (90. * (float)frame/maxframe),1,0,0);

        if(!dlID){

            dlID=glGenLists(1);
            glNewList(dlID,GL_COMPILE_AND_EXECUTE);
            Drawing::drawCuboid(vector3<float>(0,0,0),vector3<float>(0.4,1,0.4));
            glEndList();

        }else glCallList(dlID);

        glPopMatrix();

        nextFrame();

    }
};

class ElementSwitch : public virtual GameElement
{
    SWITCH_TARGET_ARRAY targets;
    switchAnimation aniObj;
public:
    ElementSwitch(vector3<int> pos);
    ~ElementSwitch();
    void invokeCollisionEvent(Character*);
    void invokeActivateEvent();
    void invokeUpdateEvent(Character *c);
    void activate();
    void deactivate();
    void render();
    void editorModeRender();
    const char* getName(){return "Switch";}

    void addTarget(GameElement*);
    void removeTarget(GameElement*);
    void removeTarget(int index);
    SWITCH_TARGET_ARRAY& getTargets(){return targets;}
};

#endif // ELEMENTSWITCH_H
